//
//  RKBackgroundRequestTest.m
//  MissPaparazzi
//
//  Created by Denis Liger on 8/23/12.
//  Copyright (c) 2012 Pr-App.com. All rights reserved.
//

//#import <RestKit/RestKit.h>
#import "RKBackgroundRequestTest.h"

@implementation RKBackgroundRequestTest

- (void)setUp
{
    [super setUp];
    
    // Set-up code here.
    done = NO;
}

- (void)tearDown
{
    // Tear-down code here.
    
    [super tearDown];
}


- (void)testBackgroundRequest
{
    /*
    RKClient *client = [RKClient clientWithBaseURL:[NSURL URLWithString:@"http://dcwc.pr-appdv.com"]];
    [RKClient setSharedClient:client];    
    
    RKRequest *request = [[RKClient sharedClient] requestWithResourcePath:@"/"];
    request.delegate = self;
    //request.backgroundPolicy = RKRequestBackgroundPolicyContinue;
    [request send];
    
    //STAssertTrue([self waitForCompletion:5.0], @"Failed to get any results in time");
     */

}

- (BOOL)waitForCompletion:(NSTimeInterval)timeoutSecs {
    NSDate *timeoutDate = [NSDate dateWithTimeIntervalSinceNow:timeoutSecs];
    
    do {
        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:timeoutDate];
        if([timeoutDate timeIntervalSinceNow] < 0.0)
            break;
    } while (!done);
    
    return done;
}

/*
- (void)requestDidStartLoad:(RKRequest *)request
{
    NSLog(@"Sent request with background policy %d at %@", request.backgroundPolicy, [NSDate date]);

}

- (void)requestDidTimeout:(RKRequest *)request
{
    NSLog(@"Request timed out during background processing");

}

- (void)requestDidCancelLoad:(RKRequest *)request
{
    NSLog(@"Request canceled");

}

- (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response
{
    NSLog(@"Request completed with response: %@", [response bodyAsString]);
    STAssertNotNil([response bodyAsString], @"Response shoud be not empty");

}

- (void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error
{
    NSLog(@"Request failed with error: %@", [error localizedDescription]);
    STAssertTrue(FALSE, @"Failed to load website content");

}
 */

@end
